package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.Roleinfo;
import com.dao.RoleDao;

/**
 * 角色添加
 */
@WebServlet("/AddroleServlet.do")
public class AddroleServlet extends HttpServlet {
	private RoleDao dao=new RoleDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String roleName=request.getParameter("roleName");
		String des=request.getParameter("des");
		Roleinfo roleinfo=new Roleinfo();
		roleinfo.setRoleName(roleName);
		roleinfo.setDes(des);
		int reat=dao.addRole(roleinfo);
		if(reat==1) {
			request.setAttribute("msg", "角色创建成功");
			request.getRequestDispatcher("/perm/role_add.jsp").forward(request,response);
		}else {
			request.setAttribute("msg", "角色创建失败");
			request.getRequestDispatcher("/perm/role_add.jsp").forward(request,response);
		}
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}

}
